# coding = utf-8
# File date: Hi_2022/11/22 22:33
# File_name: GUI_log.py
import sys
import time
from loguru import logger


def log_out():
    """
    设置log,返回loger直接调用即可
    logger.trace("'trace'级别日志,严重度值5")
    logger.debug("'debug'级别日志,严重度值10")
    logger.info("'info'级别日志,严重度值20")
    logger.success("'success'级别日志,严重度值25")
    logger.warning("'warning'级别日志,严重度值30")
    logger.error("'error'级别日志,严重度值40")
    logger.critical("'critical'级别日志,严重度值50")
    """
    log_format = "<level> {time:YYYY-MM-DD HH:mm:ss.ms} | {level} | ThreadID-{thread} | {module}.{function}:{line} | {message} </level>"
    logger.remove()  # 先删除默认样式
    logger.add(sys.stdout, level=25, format=log_format, colorize=True)  # 输出到控制台,并设置输出最低为5，自定义日志颜色

    # 每天创建log文件,并设置最低输出为5
    current_timestamp = time.time()
    format_time = time.localtime(current_timestamp)
    file_name = f"./record/log/{time.strftime('%Y%m%d', format_time)}.log"
    logger.add(file_name, rotation='00:00', level=5, format=log_format)
    return logger
